home *** CD-ROM | disk | FTP | other *** search
- unit Array4U;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, Grids, StdCtrls, Array4U2;
-
- type
- TArray4MainForm = class(TForm)
- ListBox1: TListBox;
- btnResizeArray: TButton;
- btnFillArray: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnResizeArrayClick(Sender: TObject);
- procedure btnFillArrayClick(Sender: TObject);
- private
- MyArray: TIntegerArray;
- procedure DisplayArray;
- end;
-
- var
- Array4MainForm: TArray4MainForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TArray4MainForm.FormCreate(Sender: TObject);
- begin
- MyArray := TIntegerArray.Create(
- StrToInt(InputBox(
- 'Enter your array dimensions',
- 'Number of elements:', '10')));
- btnFillArray.Click; { Pretend to push the array filling button }
- DisplayArray
- end;
-
- procedure TArray4MainForm.FormDestroy(Sender: TObject);
- begin
- MyArray.Free
- end;
-
- procedure TArray4MainForm.btnResizeArrayClick(Sender: TObject);
- begin
- MyArray.Size := StrToInt(InputBox(
- 'Enter your new array dimensions',
- 'Number of elements:', '20'));
- DisplayArray
- end;
-
- procedure TArray4MainForm.btnFillArrayClick(Sender: TObject);
- var
- Loop: Integer;
- begin
- for Loop := 0 to Pred(MyArray.Size) do
- MyArray[Loop] := Loop;
- DisplayArray
- end;
-
- procedure TArray4MainForm.DisplayArray;
- var
- Loop: Integer;
- begin
- with ListBox1, Items do
- begin
- BeginUpdate;
- try
- Clear;
- for Loop := 0 to Pred(MyArray.Size) do
- Add(IntToStr(MyArray[Loop]));
- ItemIndex := Pred(MyArray.Size)
- finally
- EndUpdate
- end
- end
- end;
-
- end.
-